#ifndef _THREAD_POOL_H_
#define _THREAD_POOL_H_

#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

#include <errno.h>
#include <pthread.h>

#define MAX_WAITING_TASKS	1000  //最大等待任务数
#define MAX_ACTIVE_THREADS	20  //最大线程数
#define BUFSIZE 100  //数据buf的大小
#define PATHSIZE 100  

struct task
{
	void *(*do_task)(void *arg);  //线程执行的函数
	void *arg;   //函数的参数

	struct task *next;
};

typedef struct thread_pool
{
	pthread_mutex_t lock;  //互斥锁
	pthread_cond_t  cond;  //条件变量

	bool shutdown;  //线程池销毁标记

	struct task *task_list; //任务链队列指针

	pthread_t *tids;	//线程ID存放位置

	unsigned max_waiting_tasks;	//最大等待任务数
	unsigned waiting_tasks;	//任务链队列中等待的任务
	unsigned active_threads;	//当前活跃线程个数
}thread_pool;


bool init_pool(thread_pool *pool, unsigned int threads_number);
bool add_task(thread_pool *pool, void *(*do_task)(void *arg), void *task);
int  add_thread(thread_pool *pool, unsigned int additional_threads_number);
int  remove_thread(thread_pool *pool, unsigned int removing_threads_number);
bool destroy_pool(thread_pool *pool);

void *routine(void *arg);


#endif
